$(function () {
    $("#jqGrid").jqGrid({
        url: '../socialsecurityareabasicupdate/list',
        datatype: "json",
        colModel: [
            { label: 'id', name: 'id', index: 'id', key: true,width: 60 ,hidden:true},
            { label: '省份', name: 'province', index: 'province',hidden:true },
            { label: '城市', name: 'city', index: 'city',hidden:true },
            { label: '地区', name: 'district', index: 'district',hidden:true },
            { label: '省份', name: 'provincename', index: 'provincename' },
            { label: '城市', name: 'cityname', index: 'cityname' },
            { label: '地区', name: 'districtname', index: 'districtname' },
            { label: '年份', name: 'year', index: 'year',width: 60 },
            { label: '月份', name: 'month', index: 'month',width: 60 },
            { label: '养老保险基数', name: 'yanglbxBasic', index: 'yanglbx_basic',width: 100 },
            { label: '养老保险单位比例', name: 'yanglbxDwbl', index: 'yanglbx_dwbl',width: 125  },
            { label: '养老保险个人比例', name: 'yanglbxGrbl', index: 'yanglbx_grbl',width: 125 },
            { label: '医疗保险基数', name: 'yilbxBasic', index: 'yilbx_basic' ,width: 100 },
            { label: '医疗保险单位比例', name: 'yilbxDwbl', index: 'yilbx_dwbl' ,width: 125},
            { label: '医疗保险个人比例', name: 'yilbxGrbl', index: 'yilbx_grbl',width: 125 },
            { label: '失业保险基数', name: 'shiybxBasic', index: 'shiybx_basic',width: 100  },
            { label: '失业保险单位比例', name: 'shiybxDwbl', index: 'shiybx_dwbl' ,width: 125},
            { label: '失业保险个人比例', name: 'shiybxGrbl', index: 'shiybx_grbl' ,width: 125},
            { label: '工伤保险基数', name: 'gongsbxBasic', index: 'gongsbx_basic' ,width: 100 },
            { label: '工伤保险单位比例', name: 'gongsbxDwbl', index: 'gongsbx_dwbl',width: 125 },
            { label: '工伤保险个人比例', name: 'gongsbxGrbl', index: 'gongsbx_grbl',width: 125 },
            { label: '生育保险基数', name: 'shengybxBasic', index: 'shengybx_basic' ,width: 100},
            { label: '生育保险单位比例', name: 'shengybxDwbl', index: 'shengybx_dwbl',width: 125 },
            { label: '生育保险个人比例', name: 'shengybxGrbl', index: 'shengybx_grbl' ,width: 125},
            { label: '公积金基数', name: 'gongjjBasic', index: 'gongjj_basic' ,width: 90},
            { label: '公积金单位比例', name: 'gongjjDwbl', index: 'gongjj_dwbl' ,width: 115},
            { label: '公积金个人比例', name: 'gongjjGrbl', index: 'gongjj_grbl',width: 115 },
            { label: '大病基数', name: 'dabinBasic', index: 'dabin_basic' ,width: 80},
            { label: '大病单位比例', name: 'dabinDwbl', index: 'dabin_dwbl',width: 100  },
            { label: '大病个人比例', name: 'dabinGrbl', index: 'dabin_grbl',width: 100  },
            { label: '五险合一基数', name: 'totalBasic', index: 'total_basic',width: 100  },
            { label: '五险合一单位比例', name: 'totalDwbl', index: 'total_dwbl' ,width: 125},
            { label: '五险合一个人比例', name: 'totalGrbl', index: 'total_grbl' ,width: 125},
            { label: '是否五险合一', name: 'istotal', index: 'istotal',width: 100,
                formatter:function(v){
                    if(v=="0"){
                        return "不是";
                    }else if(v=="1"){
                        return "是"
                    }else{
                    	return "";
					}
                } },
            { label: '养老保险基数(新)', name: 'yanglbxBasicNew', index: 'yanglbx_basic_new' ,width: 120},
			{ label: '养老保险单位比例(新)', name: 'yanglbxDwblNew', index: 'yanglbx_dwbl_new', width: 150 },
			{ label: '养老保险个人比例(新)', name: 'yanglbxGrblNew', index: 'yanglbx_grbl_new', width: 150 },
			{ label: '医疗保险基数(新)', name: 'yilbxBasicNew', index: 'yilbx_basic_new',width: 120 },
			{ label: '医疗保险单位比例(新)', name: 'yilbxDwblNew', index: 'yilbx_dwbl_new', width: 150 },
			{ label: '医疗保险个人比例(新)', name: 'yilbxGrblNew', index: 'yilbx_grbl_new', width: 150 },
			{ label: '失业保险基数(新)', name: 'shiybxBasicNew', index: 'shiybx_basic_new',width: 120},
			{ label: '失业保险单位比例(新)', name: 'shiybxDwblNew', index: 'shiybx_dwbl_new', width: 150 },
			{ label: '失业保险个人比例(新)', name: 'shiybxGrblNew', index: 'shiybx_grbl_new', width: 150 },
			{ label: '工伤保险基数(新)', name: 'gongsbxBasicNew', index: 'gongsbx_basic_new',width: 120},
			{ label: '工伤保险单位比例(新)', name: 'gongsbxDwblNew', index: 'gongsbx_dwbl_new', width: 150 },
			{ label: '工伤保险个人比例(新)', name: 'gongsbxGrblNew', index: 'gongsbx_grbl_new', width: 150 },
			{ label: '生育保险基数(新)', name: 'shengybxBasicNew', index: 'shengybx_basic_new', width: 120 },
			{ label: '生育保险单位比例(新)', name: 'shengybxDwblNew', index: 'shengybx_dwbl_new', width: 150 },
			{ label: '生育保险个人比例(新)', name: 'shengybxGrblNew', index: 'shengybx_grbl_new', width: 150 },
			{ label: '公积金基数(新)', name: 'gongjjBasicNew', index: 'gongjj_basic_new', width: 110 },
			{ label: '公积金单位比例(新)', name: 'gongjjDwblNew', index: 'gongjj_dwbl_new', width: 135 },
			{ label: '公积金个人比例(新)', name: 'gongjjGrblNew', index: 'gongjj_grbl_new', width: 135 },
			{ label: '大病基数(新)', name: 'dabinBasicNew', index: 'dabin_basic_new', width: 100 },
			{ label: '大病单位比例(新)', name: 'dabinDwblNew', index: 'dabin_dwbl_new', width: 120 },
			{ label: '大病个人比例(新)', name: 'dabinGrblNew', index: 'dabin_grbl_new', width: 120 },
			{ label: '五险合一基数(新)', name: 'totalBasicNew', index: 'total_basic_new', width: 120 },
			{ label: '五险合一单位比例(新)', name: 'totalDwblNew', index: 'total_dwbl_new', width: 150 },
			{ label: '五险合一个人比例(新)', name: 'totalGrblNew', index: 'total_grbl_new', width: 150 },
			{ label: '是否五险合一(新)', name: 'istotalNew', index: 'istotal_new', width: 120,
                formatter:function(v){
                    if(v=="0"){
                        return "不是";
                    }else if(v=="1"){
                        return "是"
                    }else{
                        return "";
                    }
                } },
			{ label: '备注', name: 'remark', index: 'remark', width: 80 }
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        shrinkToFit:false,
        autoScroll: false,

        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        //	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
    vm.getListinfo(1,'prov');
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
        provinceList:{},
        cityList:{},
        districtList:{},
		socialSecurityAreaBasicUpdate: {},
        q:{
            dateRange:null,
            province:null,
            city:null,
            district:null,
            year:null,
            month:null
        }
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.socialSecurityAreaBasicUpdate = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.socialSecurityAreaBasicUpdate.id == null ? "../socialsecurityareabasicupdate/save" : "../socialsecurityareabasicupdate/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.socialSecurityAreaBasicUpdate),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../socialsecurityareabasicupdate/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../socialsecurityareabasicupdate/info/"+id, function(r){
                vm.socialSecurityAreaBasicUpdate = r.socialSecurityAreaBasicUpdate;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{
                    declareStartDateStr:vm.q.declareStartDateStr,
                    declareeEndDateStr:vm.q.declareeEndDateStr,
                    province: vm.q.province,
                    city: vm.q.city,
                    district:vm.q.district,
                    year: vm.q.year,
                    month:vm.q.month
                },
                page:page
            }).trigger("reloadGrid");
		},
        getSelectCityByPro: function(val){
            vm.getListinfo(val.target.value,'city');
        },
        getSelectDistByCity: function(val){
            vm.getListinfo(val.target.value,'district');
        },
        getListinfo: function(pid,type){
            $.get("../socialsecurityareabasic/getListinfo/"+pid, function (r) {
                if(type=='prov'){
                    vm.provinceList = r.map;
                }else if(type=='city'){
                    vm.cityList = r.map;
                }else if(type=="district"){
                    vm.districtList = r.map;
                }

            });
        },
        dateChange:function(val){
            vm.q.declareStartDateStr=val.split(" - ")[0];
            vm.q.declareeEndDateStr=val.split(" - ")[1];
        }
	}
});